<template>
  <div class="courier">
    <div class="courier-head">
      <el-form :inline="true" class="courier-head-form">
        <el-form-item label="快递员账号:" style="width: 30%" prop="account">
          <el-input v-model="courierForm.account" placeholder="请输入快递员账号" style="width: 130%" />
        </el-form-item>
        <el-form-item label="快递员姓名:" style="width: 30%" prop="name">
          <el-input v-model="courierForm.name" placeholder="请输入快递员姓名" style="width: 130%" />
        </el-form-item>
        <el-form-item label="快递员手机号:" style="width: 30%" prop="phone">
          <el-input v-model="courierForm.phone" placeholder="请输入快递员手机号" style="width: 130%" />
        </el-form-item>
        <el-form-item label="所属机构" style="width: 30%" prop="agentId">
          <el-select
            v-model="courierForm.agentId"
            placeholder="请选择所属机构"
            style="width: 130%"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="getCourier">搜索</el-button>
        </el-form-item>
        <el-form-item>
          <el-button>重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="courier-body">
      <el-table style="width: 100%" :data="courierData.items">
        <el-table-column label="序号" width="80" type="index" />
        <el-table-column label="快递员账号" width="170" prop="account" />
        <el-table-column label="快递员姓名" width="270" prop="name" />
        <el-table-column label="快递员手机号" width="220" prop="mobile" />
        <el-table-column label="所属机构" width="300" prop="agency.name" />
        <el-table-column label="工作状态" width="180" prop="status" />
        <el-table-column fixed="right" label="操作" width="120">
          <template v-slot>
            <el-button type="text" size="small">作业分布范围</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="courierForm.page"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="Number(courierData.counts)"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>

    <div class="courier-foot">
      <span>江苏传智博客教育科技股份有限公司</span>
      <span>版权所有Copyright 2006-2022 All Rights Reserved</span>
      <span>苏ICP备16007882号-11</span>
    </div>
  </div>
</template>

<script>
import { getCourier, getInstitution } from '@/api/courier'
export default {
  data() {
    return {
      courierForm: {
        page: 1,
        pageSize: 10,
        name: '',
        agentId: '',
        phone: '',
        account: ''
      },
      // 快递员分页详情
      courierData: {},
      // 树状机构详情
      options: [],
      tableData: [
        {
          operate: '操作'
        }
      ]
    }
  },
  created() {
    // 调用获取快递员分页详情方法
    this.getCourier()
    // 调用获取树状机构详情方法
    this.getInstitution()
  },
  methods: {
    // 获取快递员分页详情方法
    async getCourier() {
      // 发送获取快递员分页详情请求
      this.courierData = await getCourier(this.courierForm)
    },
    // 获取树状机构详情方法
    async getInstitution() {
      const data = await getInstitution()
      this.options = JSON.parse(data)
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
    },
    async handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.courierForm.page = val
      this.getCourier()
    }
  }
}
</script>

<style scoped lang="scss">
.courier {
  font-weight: 700;
  background-color: #f3f5f9;

  .courier-head {
    margin: 10px 20px 20px 20px;
    width: 100%;
    height: 141px;
    padding: 20px 20px 20px 40px;
    background-color: #fff;

    .courier-head-form {
      display: flex;
      flex-wrap: wrap;
    }
  }

  .courier-body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin: 20px;
    width: 100%;
    padding: 20px 20px 20px 20px;
    background-color: #fff;

    .el-table {
      align-self: center;
    }

    .el-pagination {
      align-self: center;
      margin-top: 20px;
    }
  }

  .courier-foot {
    margin-left: 330px;
    bottom: 10px;
    font-size: 14px;
    color: #bac0cd;
    font-weight: 400;
  }
}
</style>
